exports.validatePassword = function(rule, value, callback) {
  var reg = new RegExp('^(((?=.*[a-zA-Z])(?=.*[0-9]))|((?=.*[0-9])(?=.*\\W))|((?=.*[a-zA-Z])(?=.*\\W))).{6,20}$', 'g');
  var flag = reg.test(value);
  var repeat = 3;
  if (flag) {
    var arr = value.split('');
    var count = 0;
    var ascCount = 0;
    var descCount = 0;
    for (var i = 0; i + repeat <= arr.length; i++) {
      count = 0;
      ascCount = 0;
      descCount = 0;
      for (var j = 0; j < repeat - 1; j++) {
        if (arr[i + j].charCodeAt() === arr[i + j + 1].charCodeAt()) {
          count++;
          if (count === repeat - 1) {
            callback(new Error('不能出现连续3位及以上相同字母或者数字'));
          }
        }
      }
      for (var k = 0; k < repeat - 1; k++) {
        if (arr[i + k].charCodeAt() === (arr[i + k + 1].charCodeAt() + 1)) {
          ascCount++;
          if (ascCount === repeat - 1) {
            callback(new Error('不能出现连续3位及以上连续倒序字母或者数字'));
          }
        }
      }
      for (var q = 0; q < repeat - 1; q++) {
        if (arr[i + q].charCodeAt() === (arr[i + q + 1].charCodeAt() - 1)) {
          descCount++;
          if (descCount === repeat - 1) {
            callback(new Error('不能出现连续3位及以上连续正序字母或者数字'));
          }
        }
      }
    }
  } else {
    callback(new Error('密码为6到20位并且字母、数字、特殊字符三项中有两项'));
  }
  callback();
};
